﻿/* eslint-disable semi,standard/object-curly-even-spacing,import/no-duplicates,import/first */
/* eslint-disable semi,standard/object-curly-even-spacing,import/no-duplicates */
/* eslint-disable semi,standard/object-curly-even-spacing */
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import wx from 'weixin-js-sdk'

// eslint-disable-next-line import/no-duplicates
import Axios from 'axios'
import echarts from 'echarts'
import RegisterComponents from './components/RegisterComponents'
import Mint from 'mint-ui'
import QRCode from 'qrcode'
import 'mint-ui/lib/style.css'
import Countdown from './components/Countdown.vue'
Vue.use(Mint)
Vue.use(QRCode)

import axios from 'axios'
Vue.component('Countdown', Countdown)
Vue.prototype.$http = axios
Vue.prototype.router = router
Vue.config.productionTip = false
import Vuex from 'vuex'
import store from './vuex/MemberList'

Vue.config.productionTip = false
Vue.use(Vuex)
Vue.use(Mint)
Vue.prototype.$echarts = echarts
Vue.prototype.$http = Axios

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  // 组件渲染之前执行在通用类注册中的方法
  components: {App},
  created(){
    router.beforeEach((to, from, next) => {

      if (to.meta.title) {
        document.title = to.meta.title
        // window.localStorage.histroyUrl = window.location.href;
      }
      document.documentElement.scrollTop = 0
      document.body.scrollTop = 0
      window.scrollTo(0, 0)
      next()
    })
  },
  beforeMount () {
    RegisterComponents.register()
  },
  methods: {
    // 授权登录
    login (userType) {
      let jsonValue = JSON.stringify({
        'c': '10005',
        'p': {
          'userType': userType,
          'openid': window.localStorage.openid
//            "access_token": window.localStorage.access_token
        }
      })
      this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
        console.log(res)
        if (res.data.p.isTrue === true) {
          // this.showAlert = true
          // this.alertText = '赚多多将获取您的微信部分信息'
          // this.alertText = '登陆成功'
          window.localStorage.loginP = JSON.stringify(res.data.p)
          window.localStorage.data = JSON.stringify(res.data.p.user)
          localStorage.setItem('token', res.data.p.token)
        } else {
          // this.showAlert = true
          this.alertText = res.data.p.errorMsg
        }
      }, (res) => {
        this.showAlert = true
        this.alertText = '网络错误'
      })
    }
  }
})
